package cn.hollis.nft.turbo.base.exception;

/**
 * 业务异常
 *
 * @author Hollis
 */
public class BizException extends RuntimeException {

    // 每个异常类里都有 ErrorCode 对象，ErrorCode是个接口，包含异常码和异常信息。实现类使用 Enum 枚举类，这样可以控制都有哪些异常信息，新增一个异常信息就在枚举类中加一个对象即可
    private ErrorCode errorCode;

    public BizException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.errorCode = errorCode;
    }

    public BizException(String message, ErrorCode errorCode) {
        super(message);
        this.errorCode = errorCode;
    }

    public BizException(String message, Throwable cause, ErrorCode errorCode) {
        super(message, cause);
        this.errorCode = errorCode;
    }

    public BizException(Throwable cause, ErrorCode errorCode) {
        super(cause);
        this.errorCode = errorCode;
    }

    public BizException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, ErrorCode errorCode) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.errorCode = errorCode;
    }

    public ErrorCode getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(ErrorCode errorCode) {
        this.errorCode = errorCode;
    }
}
